package de.koller.reason.render;

import de.koller.oceanFramework.plain.util.IRRender;
import de.koller.oceanFramework.plain.util.RViewport;
import de.koller.oceanFramework.plain.util.RFrame;
import de.koller.reason.RNode;
import de.koller.reason.render.obj.Polygon;
import de.koller.reason.render.ray.IRenderData;
import de.koller.reason.render.ray.RayRenderer;
import java.awt.Graphics2D;
import java.util.HashSet;
import java.util.Set;

public class RRender extends RNode implements IRRender, IRenderData {

	private final int viewportW = 800, viewportH = 600;
	
	private final RFrame frame = new RFrame( viewportW, 600, this );
	private final RViewport viewport = new RViewport( viewportW, viewportH );
	
	//private final PerspectiveProjection projection = new PerspectiveProjection();
	private final Set<Polygon> polygons = new HashSet<>();
	//private final RenderPipeline renderPipeline = new RenderPipeline( viewport.raster, projection );
	private final RayRenderer rayrender = new RayRenderer();
	
	@Override
	protected void init() {
		super.init();
		
		frame.init();
	}

	@Override
	protected void release() {
		super.release();
		
		frame.release();
		viewport.release();
	}
	
	
	public void renderThis( int delta ) {
		
//		renderPipeline.preRenderStep();
//		
//		for( Polygon o : polygons )
//			renderPipeline.renderPolygon( o );
//		polygons.clear();
//		
//		renderPipeline.finishRenderStep();
	
		rayrender.render( this, viewport.raster );
		frame.render( delta );
		polygons.clear();
	}

	@Override
	public Set<Polygon> getPolygons() {
		return polygons;
	}
	
	public void renderPolygon( Polygon polygon ) {
		polygons.add( polygon );
	}
	
	@Override
	public void renderContent( Graphics2D g ) {		
		g.drawImage( viewport.bitmap, 0, 0, frame.width, frame.height, null );
	}

	@Override
	public void close() {
		this.rroot.stop();
	}
	
	
}
